//
//  TransferRecodeTableViewController.m
//  EasyToTesco2.0
//
//  Created by knew on 2017/6/8.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "TransferRecodeTableViewController.h"
#import "TotalRecordWholeAndPointTableViewCell.h"
#import "TransferModel.h"


@interface TransferRecodeTableViewController ()
{
    NSInteger _page;
    UIImageView *noDrawImage;
    BOOL _judgeFirst;

}

@property (nonatomic,strong)NSMutableArray *transferArray;

@end

@implementation TransferRecodeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"转账记录";
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _page = 1;
    self.tableView.mj_footer = [TopPullRefreshAnaimation footerWithRefreshingTarget:self refreshingAction:@selector(loadTransferMoreListData)];
    [self loadTransferRecodeData];

    _judgeFirst = YES;
}

- (void)loadTransferMoreListData {
    _page++;
    [self loadTransferRecodeData];
}

- (void)loadTransferRecodeData {
    NSDictionary *params = @{
                             @"username":USERNAME,
                             @"page":[NSString stringWithFormat:@"%ld",_page]
                             };
    
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/user/merchantPayHistory" completeBlock:^(id object) {
        
        NSArray *array = object[@"data"];
        [self.tableView.mj_footer endRefreshing];
        if (array.count) {
            for (NSDictionary *dict in array) {
                TransferModel *model = [[TransferModel alloc] initWithDictionary:dict error:nil];
                [self.transferArray addObject:model];
            }
        } else {
            [self showHint:@"暂无更多数据"];
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }
        
        if (!array.count && _judgeFirst) {
            noDrawImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_NoRecord"]];
            [self.view addSubview:noDrawImage];
            self.tableView.backgroundColor = BACKGROUND_COLOR;
            
            [noDrawImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view.mas_centerX);
                make.centerY.equalTo(self.view.mas_centerY).offset(-HEIGHT/8);
                make.width.mas_equalTo(WIDTH/1.5);
                make.height.mas_equalTo(WIDTH/2.4);
            }];
        }
        _judgeFirst = NO;
        [self.tableView reloadData];
    }];
    
    /*
     
     
     */
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.transferArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TotalRecordWholeAndPointTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[TotalRecordWholeAndPointTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    TransferModel *model = self.transferArray[indexPath.row];
    cell.transferModel = model;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 140;
}

- (NSMutableArray *)transferArray {
    if (!_transferArray) {
        _transferArray = [NSMutableArray array];
    }
    return _transferArray;
}

@end
